home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MPW_TOOL
/
TOOLS
/
TOOLS_WI
/
ICON_8
/
MEMMON_F
/
MBATCH.C
< prev
next >
Wrap
Text File
|
1990-03-02
|
3KB
|
157 lines
/*
* mbatch.c: basic interface for batch-mode output.
*/
#include "memmon.h"
static int nframes = 0; /* number of images written */
/*
* Text buffer.
*/
static char tbuf[TextLines][TextLength + 1]; /* text chars */
static unsigned char tfg[TextLines][TextLength + 1]; /* foreground color */
static unsigned char tbg[TextLines][TextLength + 1]; /* background color */
/*
* Memory map buffer.
*/
static unsigned char *mbuf; /* pixel color buffer */
static word mbufsiz = 0; /* current allocated size */
/*
* devmap() - load color map into device.
*/
novalue devmap()
{
/* nothing to do */
}
/*
* devflood(c) - fill image with color c.
*/
novalue devflood(c)
int c;
{
word n;
n = (word)memheight * (word)width; /* max display w/o new refresh */
if (n > mbufsiz) {
if (mbuf)
free((char *)mbuf);
n = (word)memheight * (word)width;
mbuf = (unsigned char *)malloc((msize)n);
if (!mbuf) {
fprintf(stderr, "%s: out of memory", progname);
exit(ErrorExit);
}
mbufsiz = n;
}
memfill((char *)mbuf, c, (word)mbufsiz);
memfill((char *)tbuf, 0, (word)(TextLines * TextLength));
memfill((char *)tbg, c, (word)(TextLines * TextLength));
}
/*
* devpaint(start, n, color, b) - paint n pixels in given color.
* If b >= 0, the last pixel is to be that color instead (for a border)
*/
novalue devpaint(s, n, c, b)
word s, n;
int c, b;
{
unsigned char *p;
if (b >= 0) /* if border, decr total count */
n--;
p = mbuf + s;
while (n--) /* fill pixels */
*p++ = c;
if (b >= 0) /* if border, set its value */
*p++ = b;
}
/*
* devtext(string, row, col, fgcolr, bgcolr) - write text data.
*/
novalue devtext(s, row, col, fg, bg)
char *s;
int row, col, fg, bg;
{
int n;
n = strlen(s) + 1;
while (n--) { /* copy including terminator */
tbuf[row][col] = *s++;
tfg[row][col] = fg;
tbg[row][col] = bg;
if (col++ > TextLength)
break; /* but no wraparound */
}
}
/*
* devsnap() - take a snapshot of the current display.
*/
novalue devsnap()
{
int c, row, col, k;
batbegin(); /* begin batch frame */
/*
* identify text strings and pass individually
*/
if (textrow > 0) {
for (row = 0; row < TextLines; row++) { /* for each text line */
col = 0;
while (col < TextLength) {
if (tbuf[row][col] == '\0' || tfg[row][col] == tbg[row][col])
col++; /* skip unused text positions */
else {
for (k = col;
k < TextLength && tfg[row][k]==tfg[row][col] && tbuf[row][k];
k++)
; /* find run of one color */
c = tbuf[row][k];
tbuf[row][k] = '\0'; /* temporarily terminate string */
battext(tbuf[row] + col, row, col,
(int)tfg[row][col], (int)tbg[row][col]);
tbuf[row][k] = c; /* restore text buffer */
col = k;
}
}
}
}
/*
* dump memory to finish up
*/
batmem(mbuf); /* write memory dump, finish frame */
nframes++;
}
/*
* devflush() - flush output. (No action needed.)
*/
novalue devflush()
{
}
/*
* devterm() - terminate graphics.
*/
novalue devterm()
{
fprintf(stderr, "%d %s written\n", nframes, (nframes==1)?"frame":"frames");
batterm();
}